package com.tyd.cams.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.tyd.cams.JsRecyclerAdapter;
import com.tyd.cams.R;
import com.tyd.cams.entity.JsInfoBean;
import com.tyd.cams.entity.JxLouBeans;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: TYD
 * @作者: 唐YaDong
 * @date: 2021/3/13 12:40
 * @description：JxlRecyclerAdapter
 * @描述：JxlRecyclerAdapter
 * @版本：1.0
 */
public class JxlRecyclerAdapter extends RecyclerView.Adapter<JxlRecyclerAdapter.ViewHplder> {
    Context context;
    List<JxLouBeans> jiaoXloubeanList;
    LayoutInflater layoutInflater;

    public JxlRecyclerAdapter(Context context, List<JxLouBeans> jiaoXloubeanList) {
        this.context = context;
        this.jiaoXloubeanList = jiaoXloubeanList;
    }

    @NonNull
    @Override
    public ViewHplder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = layoutInflater.from(parent.getContext()).inflate(R.layout.js_list1, parent
                , false);
        return new ViewHplder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHplder holder, int position) {

        JxLouBeans jxLouBeans = jiaoXloubeanList.get(position);
        holder.jxlName.setText(jxLouBeans.getBname());
        JsRecyclerAdapter jsRecyclerAdapter = new JsRecyclerAdapter(context, jxLouBeans.getCroominfo());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        holder.JsInfoRecyclerView.setLayoutManager(linearLayoutManager);
        holder.JsInfoRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        holder.JsInfoRecyclerView.setAdapter(jsRecyclerAdapter);
        holder.JsInfoRecyclerView.setVisibility(View.VISIBLE);

/*        for (List<jxLouBeans> map : jiaoXloubeanList) {
            // List<JsInfoBean> jsList = new ArrayList<JsInfoBean>();
            for (String s : map.keySet()) {
                List<JsInfoBean> jsList = new ArrayList<JsInfoBean>();
                System.out.println("s" + s);
                for (JsInfoBean jsInfoBean : map.get(s)) {
                    System.out.println("教室：" + jsInfoBean.toString());
                    jsList.add(jsInfoBean);
                }
                // 关键代码
                //////////////////////////////////////////////////
                JsRecyclerAdapter jsRecyclerAdapter = new JsRecyclerAdapter(context, jsList);
                LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
                linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
//                holder.JsInfoRecyclerView.setLayoutManager(linearLayoutManager);
                holder.JsInfoRecyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));

                holder.JsInfoRecyclerView.setAdapter(jsRecyclerAdapter);
//                holder.JsInfoRecyclerView.setVisibility(View.VISIBLE);
            }
            //        holder.jxlName.setText(jxLouBeans.getBid());
//        setjsInfo(jxLouBeans.getBid());

        }*/


    }

    @Override
    public int getItemCount() {
        return jiaoXloubeanList == null ? 0 : jiaoXloubeanList.size();
    }

    public class ViewHplder extends RecyclerView.ViewHolder {
        TextView jxlName;
        TextView jxlid;
        RecyclerView JsInfoRecyclerView;

        public ViewHplder(@NonNull View itemView) {
            super(itemView);
            jxlName = itemView.findViewById(R.id.js_name);
            jxlid = itemView.findViewById(R.id.jxl_id);
            JsInfoRecyclerView = itemView.findViewById(R.id.js_Recycle);
        }
    }
}
